from machine import Pin,ADC
class Shield:
    def __init__(self):
        self.adc12=ADC(Pin(12))
        self.adc13 = ADC(Pin(13))
        self.adc12.equ(ADC.EQU_MODEL_8)
        self.adc12.atten(ADC.CUR_BAIS_DEFAULT)
        self.adc13.equ(ADC.EQU_MODEL_8)
        self.adc13.atten(ADC.CUR_BAIS_DEFAULT)
        self.pA = Pin(2, Pin.IN)
        self.pB = Pin(1, Pin.IN)
        self.pD = Pin(14, Pin.IN)
        self.pC = Pin(0, Pin.IN)

    def read(self):
        Flag = 0
        timelimit = utime.ticks_ms()+400
        while True:
            # print(timelimit)
            # print(utime.ticks_ms())
            if self.pA.value() == 0 and self.pB.value() == 0 and self.pD.value() == 0 and self.pC.value() == 0:
                continue
            if self.adc12.read() > 1000:
                print("right")
                Flag = 1
                break
            if self.adc12.read() < 118:
                print("left")
                Flag = 2
                break
            if self.adc13.read() > 1000:
                print("up")
                Flag = 3
                break
            if self.adc13.read() < 118:
                print("down")
                Flag = 4
                break
            if self.pA.value() == 0:
                print("is A")
                Flag = 5
                break
            if self.pB.value() == 0:
                print("is B")
                Flag = 6
                break
            if self.pC.value() == 0:
                print("is C")
                Flag = 7
                break
            if self.pD.value() == 0:
                print("is D")
                Flag = 8
                break
            if utime.ticks_ms() >= timelimit:
                print("No Operation")
                break
        return Flag